//
//  HWpinglunCommentsCell.m
//  HWanGame
//
//  Created by 陈道斌 on 2020/9/16.
//  Copyright © 2020 Chendaobin. All rights reserved.
//

#import "HWpinglunCommentsCell.h"
#import "UIImage+Extension.h"

@implementation HWpinglunCommentsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    for (int i = 0 ; i < 5; i++) {
        
        UIImageView *iamgeView  = [[UIImageView alloc]initWithFrame:CGRectMake(25+4+i*(4+8), 4, 8, 8)];
        iamgeView.image = [UIImage imageNamed:@"pingfen_weixuanzhong"];
        iamgeView.tag = 100 +i;
        [self.pingfenView addSubview:iamgeView];
      //   pingfen_weixuanzhong
        // stars_ico
    
    }
    
    
    
    
    self.icoiamgeView.layer.cornerRadius = 13;
    self.icoiamgeView.layer.masksToBounds = YES;
    
    
    self.dianzanButon = [UIButton  createNormalButtonWithFrame:CGRectMake(kScreenW-51-20-80, 2, 80, 12) Image:@"giveALike" Title:@"100" font:10 imageSize:CGSizeMake(12, 12)];
         [self.dianzanButon layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:3];
         [self.dianzanButon addTarget:self action:@selector(giveALikeTap) forControlEvents:UIControlEventTouchUpInside];
    
   //    self.dianzanButon.backgroundColor = [UIColor redColor];
    
         [self.dianzanRiQiView  addSubview: self.dianzanButon];
     
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (void) giveALikeTap {
    
    
    
    
              NSString *uid = [HWLocallyStoredData getLoginUserID];
              NSString *tString = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
            //  NSString *gidStr = [NSString stringWithFormat:@"%@",self.gameId];
              NSString *signStr = [NSString stringWithFormat:@"%@%@%@",uid,tString,@"fsd213ewdsadqwe2121213edsad"];
              NSString *signMD5 = [WMUtil md5HexDigest:signStr];
              
              NSString *type = @"0";

              NSDictionary *parametes = @{
                                
                                @"uid":uid,
                                @"t":tString,
                                @"sign":signMD5,
                                @"id":self.model.id,
                                @"ct":@"app",
                                @"ac":@"video_pinglun_zan",
                                @"ios" : @"1",
                                 @"member_id":[HWLocallyStoredData getCode],
                                
                               
                                
              };
          
              
        

              [HWWebUtils do3GetWithParameters:parametes progress:nil success:^(id response) {
                  
                 
                  
                  NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
                  
                  if ([codeStr intValue] == 1) {
                     // [MBProgressHUD showMessage:@"收藏成功" toView:self.view];
                      
                      
                   //    self.model.zan
                      
                      
                      NSString *str = [NSString stringWithFormat:@"%@",response[@"message"]];
                      
                      if ([str isEqualToString:@"取消成功"]) {
                          NSInteger zan = [self.model.zan intValue] - 1;
                          NSString *zanStr = [NSString stringWithFormat:@"%ld",zan];
                           self.model.zan = zanStr;
                          
                          
//                           [self.dianzanButon layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleTop imageTitleSpace:3];
//                           [self.dianzanButon setTitle:zanStr forState:UIControlStateNormal];
//                           [self.dianzanButon setImage:[UIImage imageNamed:@"giveALike"] forState:UIControlStateNormal];
                          
                          
                          
                          
                          UIImage   *temp =  [UIImage imageNamed:@"pingludianza_ico"];
                          //  temp = [temp scaleImageWithSize:CGSizeMake(12, 12)];
                           
                           [self.dianzanButon setImage:temp forState:UIControlStateNormal];
                           [self.dianzanButon setTitle:self.model.zan forState:UIControlStateNormal];
                           
                            [self.dianzanButon layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:3];
                          
                          
                          
                          self.model.is_zan = @"0";
               
                          
                      } else {
                          
                          NSInteger zan = [self.model.zan intValue] + 1;
                          NSString *zanStr = [NSString stringWithFormat:@"%ld",zan];
                
                          self.model.zan = zanStr;
                          
//                          [self.dianzanButon layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleTop imageTitleSpace:3];
//
//                          [self.dianzanButon setImage:[UIImage imageNamed:@"dianzangaoliang"] forState:UIControlStateNormal];
//
//                          [self.dianzanButon setTitle:zanStr forState:UIControlStateNormal];
                          
                          
                          
                           UIImage   *temp =  [UIImage imageNamed:@"xuanzhongde_ico"];
                                                  //  temp = [temp scaleImageWithSize:CGSizeMake(12, 12)];
                            [self.dianzanButon setImage:temp forState:UIControlStateNormal];
                            [self.dianzanButon setTitle:self.model.zan forState:UIControlStateNormal];
                                                   
                            [self.dianzanButon layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:3];
                                                  
                          
                          
                           self.model.is_zan = @"1";
                          
                          
                          
                          
                      }
                      
                      
    //                  NSInteger zan = [self.model.zan intValue] + 1;
    //                  NSString *zanStr = [NSString stringWithFormat:@"%ld",zan];
    //                  [self.dianzanButon setTitle:zanStr forState:UIControlStateNormal];
    //
    //
                    
                      
                      
                    
                  } else {
                      
                      
                     // [MBProgressHUD showError:@"收藏失败"];
                     [MBProgressHUD showError:response[@"message"]];
                      
                  }
               
                  
                  
              } failure:^(NSString *error) {
                 
                  
                  [MBProgressHUD showError:@"收藏失败"];
                  
              }];
    
    
    
    
    
    
    
}


- (void)setModel:(HWCommentsModel *)model {
    
    _model = model;
    
    [self.icoiamgeView sd_setImageWithURL:[NSURL URLWithString:model.face] placeholderImage:nil];
    
    self.mingchengLabel.text = [NSString stringWithFormat:@"%@",model.user_name];
    self.tubiaoImageView.hidden = YES;
    
    if ([model.is_huiyuan isEqualToString:@"1"]) {
        [self.tubiaoImageView sd_setImageWithURL:[NSURL URLWithString:model.icon] placeholderImage:nil];
        self.tubiaoImageView.hidden = NO;
    }
    // [self.tubiaoImageView sd_setImageWithURL:[NSURL URLWithString:model.icon] placeholderImage:nil];
    int point =  [model.point intValue];
    
    for (int i = 0; i < point; i++) {
         
        
       UIImageView *imagevie =    [self.pingfenView viewWithTag:i+100];
        
        
        imagevie.image  = [UIImage imageNamed:@"stars_ico"];
        
        
    }
    
      
    
    self.leirongLabel.text = [NSString stringWithFormat:@"%@",model.content];
    self.riqiLabel.text =  [NSString stringWithFormat:@"%@",model.time];
    
     
    CGSize size =   [WMUtil strName:model.zan fontSize:[UIFont systemFontOfSize:10] boundingRectWithSize:CGSizeMake(1000, 20)];
    
    self.dianzanButon.frame = CGRectMake(kScreenW-51-20-3-12-size.width, 2, 3+12+size.width, 12);
    

    
    if ([model.is_zan isEqualToString:@"0"]) {
        
       //  pingludianza_ico
        
        UIImage   *temp =  [UIImage imageNamed:@"pingludianza_ico"];
                 //  temp = [temp scaleImageWithSize:CGSizeMake(12, 12)];
                  
                  [self.dianzanButon setImage:temp forState:UIControlStateNormal];
                  [self.dianzanButon setTitle:model.zan forState:UIControlStateNormal];
                  
                   [self.dianzanButon layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:3];
                  
        
        
    } else {
        
        UIImage   *temp =  [UIImage imageNamed:@"xuanzhongde_ico"];
          //  temp = [temp scaleImageWithSize:CGSizeMake(12, 12)];
           
           [self.dianzanButon setImage:temp forState:UIControlStateNormal];
           [self.dianzanButon setTitle:model.zan forState:UIControlStateNormal];
           
            [self.dianzanButon layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:3];
           
        
    }
    
    
//    UIImage   *temp =  [UIImage imageNamed:@"xuanzhongde_ico"];
//   //  temp = [temp scaleImageWithSize:CGSizeMake(12, 12)];
//
//    [self.dianzanButon setImage:temp forState:UIControlStateNormal];
//    [self.dianzanButon setTitle:model.zan forState:UIControlStateNormal];
//
//     [self.dianzanButon layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:3];
//
    
    
}



@end
